{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to atomman: Stacking fault generator\n",
    "\n",
    "__Lucas M. Hale__, [lucas.hale@nist.gov](mailto:lucas.hale@nist.gov?Subject=ipr-demo), _Materials Science and Engineering Division, NIST_.\n",
    "    \n",
    "[Disclaimers](http://www.nist.gov/public_affairs/disclaimer.cfm) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Introduction<a id='section1'></a>\n",
    "\n",
    "This Notebook outlines the StackingFault class which generates atomic systems that can be used to evaluate stacking fault energies.  See the [4.5 Gamma surface plotting Notebook](4.5._Gamma_surface_plotting.html) for analysis and plotting of computed stacking fault energies.\n",
    "\n",
    "*Completely reworked for version 1.3.2* the new StackingFault class is a child of FreeSurface, and therefore has built-in tools for easier generation.  \n",
    "\n",
    "Documentation for the older StackingFault class can be found on github by exploring past versions of this Notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Library Imports**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "atomman version = 1.4.0\n",
      "Notebook executed on 2021-08-05\n"
     ]
    }
   ],
   "source": [
    "# Standard Python libraries\n",
    "import datetime\n",
    "\n",
    "# http://www.numpy.org/\n",
    "import numpy as np\n",
    "\n",
    "# https://github.com/usnistgov/atomman\n",
    "import atomman as am\n",
    "import atomman.unitconvert as uc\n",
    "\n",
    "# Show atomman version\n",
    "print('atomman version =', am.__version__)\n",
    "\n",
    "# Show date of Notebook execution\n",
    "print('Notebook executed on', datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Theory<a id='section2'></a>\n",
    "\n",
    "A stacking fault atomic configuration can be constructed by\n",
    "\n",
    "1. Generating a bulk crystalline system with all periodic boundaries.\n",
    "2. Slicing the system along a geometrical plane creating two ideal planar-sliced free surfaces.\n",
    "3. Specifying a geometrical fault plane that is parallel to the free surfaces and divides the atoms (roughly) in half. \n",
    "4. Rigidly shifting all atoms on one side of the fault plane by the same shift vector, $\\mathbf{d}$.\n",
    "\n",
    "The first two steps correspond with the construction of a planar-sliced free surface configuration. The corresponding theory for those steps is outlined in the [Free surface configuration generator Notebook](4.2._Free_surface_generator.html). \n",
    "\n",
    "Once the free surface has been constructed, a stacking fault configuration can be defined by specifying the location to position the fault plane, and a fault shift $\\mathbf{d}$ to apply. For the plane position, it is usually convenient to select the halfway point in the system. If the system was constructed with an even number of replicas in the direction normal to the fault/surface planes, then placing the fault plane in the middle of the system will result in the fault plane matching the free surface plane.\n",
    "\n",
    "As the fault plane can be explored in 2 dimensions, the applied shift, $\\mathbf{d}$, can be expressed using two non-parallel vectors within the fault plane, $\\mathbf{a_1}$ and $\\mathbf{a_2}$. Taking $\\mathbf{a_1}$ and $\\mathbf{a_2}$ as lattice slip vectors (i.e. vectors between two symmetrically identical lattice sites) will define a 2D cell encompassing all possible unique stacking fault shifts for the fault plane.  $\\mathbf{d}$ can then be represented using fractional coordinates, $a_1$ and $a_2$, relative to $\\mathbf{a_1}$ and $\\mathbf{a_2}$\n",
    "\n",
    "$$ \\mathbf{d} = a_1 \\mathbf{a_1} + a_2 \\mathbf{a_2} $$\n",
    "\n",
    "If the free surface configuration was generated using a primitive unit cell, then the two in-plane box vectors of the intermediate rotated cell will correspond to the shortest in-plane lattice vectors. As such, using those box vectors will result in the smallest periodic 2D cell necessary to fully explore the stacking fault map."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Class basics<a id='section3'></a>\n",
    "\n",
    "The class is set up to generate stacking fault configuration systems in three steps:\n",
    "\n",
    "1. Initialize the class and specify the (hkl) fault/surface plane and unit cell structure to use. The proper rotated cell will be generated as well as a list of shifts that can be applied.\n",
    "2. Build the free surface system by selecting the shift value corresponding to the termination planes of interest and the size of the final system.\n",
    "3. Construct stacking fault configurations by rigidly shifting all atoms on one side of the fault plane.\n",
    "\n",
    "### 3.1. StackingFault initialization\n",
    "\n",
    "Class initializer.  Identifies the proper rotations for the given hkl plane and cutboxvector, and creates the rotated cell.\n",
    "\n",
    "- __hkl__ (*array-like object*) The free surface plane to generate expressed in either 3 indices Miller (hkl) format or 4 indices Miller-Bravais (hkil) format.\n",
    "- __ucell__ (*atomman.System*) The unit cell to use in generating the system.\n",
    "- __cutboxvector__ (*str, optional*) Specifies which of the three box vectors corresponds to the out-of-plane vector.  Default value is c.\n",
    "- __maxindex__ (*int, optional*) Max uvw index value to use in identifying the best uvw set for the out-of-plane vector.  If not given, will use the largest absolute index between the given hkl and the initial in-plane vector guesses.\n",
    "- __a1vect_uvw__ (*array-like object, optional*) The crystal vector to use for one of the two shifting vectors.  If not given, will be set to the shortest in-plane box vector of rcell.\n",
    "- __a2vect_uvw__ (*array-like object, optional*) The crystal vector to use for one of the two shifting vectors.  If not given, will be set to the other in-plane box vector of rcell.\n",
    "- __conventional_setting__ (*str, optional*) Allows for rotations of a primitive unit cell to be determined from (hkl) indices specified relative to a conventional unit cell.  Allowed settings: 'p' for primitive (no conversion), 'f' for face-centered, 'i' for body-centered, and 'a', 'b', or 'c' for side-centered.  Default behavior is to perform no conversion, i.e. take (hkl) relative to the given ucell.\n",
    "- __tol__ (*float, optional*) Tolerance parameter used to round off near-zero values.  Default value is 1e-8.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2. StackingFault.surface()\n",
    "\n",
    "Generates the free surface atomic system, which is used as the basis for generating the stacking fault configuration(s).\n",
    "\n",
    "- __shift__ (*array-like object, optional*) Applies a shift to all atoms. Different values allow for free surfaces with different termination planes to be selected.\n",
    "- __vacuumwidth__ (*float, optional*) If given, the free surface is created by modifying the system's box to insert a region of vacuum with this width. This is typically used for DFT calculations where it is computationally preferable to insert a vacuum region and keep all dimensions periodic.\n",
    "- __sizemults__ (*list or tuple, optional*) The three System.supersize multipliers [a_mult, b_mult, c_mult] to use on the rotated cell to build the final system. Note that the cutboxvector sizemult must be an integer and not a tuple.  Default value is [1, 1, 1].\n",
    "- __minwidth__ (*float, optional*) If given, the sizemult along the cutboxvector will be selected such that the width of the resulting final system in that direction will be at least this value. If both sizemults and minwidth are given, then the larger of the two in the cutboxvector direction will be used. \n",
    "- __even__ (*bool, optional*) A True value means that the sizemult for cutboxvector will be made an even number by adding 1 if it is odd.  Default value is False.\n",
    "- __faultpos_rel__ (*float, optional*) The position to place the slip plane within the system given as a relative coordinate along the out-of-plane direction.  faultpos_rel and faultpos_cart cannot both be given.  Default value is 0.5 if faultpos_cart is also not given.\n",
    "- __faultpos_cart__ (*float, optional*) The position to place the slip plane within the system given as a Cartesian coordinate along the out-of-plane direction.  faultpos_rel and faultpos_cart cannot both be given."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3. StackingFault.fault()\n",
    "\n",
    "Generates a fault configuration by displacing all atoms above the slip plane.\n",
    "\n",
    "Parameters\n",
    "        \n",
    "- __a1__ (*float, optional*) The fractional coordinate of a1vect to shift by.  Default value is 0.0.\n",
    "- __a2__ (*float, optional*) The fractional coordinate of a2vect to shift by.  Default value is 0.0. \n",
    "- __outofplane__ (*float, optional*) An out-of-plane shift, given in absolute units.  Default value is 0.0.\n",
    "- __faultshift__ (*array-like object, optional*) The full shifting vector to displace the atoms above the slip plane by.  Cannot be given with a1, a2, or outofplane.\n",
    "- __minimum_r__ (*float, optional*) *Added version 1.2.7* Specifies the minimum allowed interatomic spacing across the slip plane.  If any sets of atoms are closer than this value then the outofplane shift is increased.  Default value is None, which performs no adjustment.\n",
    "\n",
    "Returns\n",
    "        \n",
    "- (*atomman.System*) The atomic configuration with stacking fault shift"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.4. StackingFault.iterfaultmap()\n",
    "\n",
    "Iterates over generalized stacking fault configurations associated with a 2D map of equally spaced a1, a2 coordinates.\n",
    "\n",
    "Parameters\n",
    "        \n",
    "- __num_a1__ (*int*) The number of a1 values to generate systems for.  Default value is 1 (only generate for a1=0.0).\n",
    "- __num_a2__ (*int*) The number of a2 values to generate systems for.  Default value is 1 (only generate for a2=0.0).\n",
    "- __outofplane__ (*float, optional*) An out-of-plane shift, given in absolute units.  Default value is 0.0.\n",
    "- __minimum_r__ (*float, optional*) *Added version 1.2.7* Specifies the minimum allowed interatomic spacing across the slip plane.  If any sets of atoms are closer than this value then the outofplane shift is increased.  Default value is None, which performs no adjustment.\n",
    "\n",
    "Yields\n",
    "        \n",
    "- __a1__ (*float*) The a1 fractional coordinate of a1vect. \n",
    "- __a2__ (*float*) The a2 fractional coordinate of a2vect. \n",
    "- (*atomman.System*) The fault configuration associated with the a1, a2 shift."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Examples<a id='section4'></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.1. fcc $\\{111\\}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.1.1. Define an fcc conventional cell and initialize a StackingFault"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = uc.set_in_units(4.05, 'angstrom')\n",
    "atoms = am.Atoms(pos=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5]])\n",
    "ucell = am.System(atoms=atoms, box=am.Box.cubic(a), scale=True, symbols='Al')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "plane_hkl = [ 1,  1,  1]\n",
    "\n",
    "sf = am.defect.StackingFault(plane_hkl, ucell)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.1.2. Check the identified rotated system\n",
    "\n",
    "The StackingFault class is a child of FreeSurface, so it has all the same attributes that you can check. In addition, default values of a1vect and a2vect are set during the class initialization.\n",
    "\n",
    "- __uvws__ are the three conventional Miller vectors used as the box vectors of the rotated system. \n",
    "- __rcell__ is the rotated cell.\n",
    "- __transform__ is the Cartesian transformation matrix associated with going from ucell to rcell.\n",
    "- __rcellwidth__ is the width of the rotated cell in the direction normal to the hkl plane.\n",
    "- __a1vect_uvw, a2vect_uvw__ are the two lattice fault vectors as crystallographic Miller vectors relative to ucell.\n",
    "- __a1vect_cart, a2vect_cart__ are the two lattice fault vectors as Cartesian vectors relative to rcell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-1.  1.  0.]\n",
      " [-1.  0.  1.]\n",
      " [ 1.  1.  1.]]\n"
     ]
    }
   ],
   "source": [
    "print(sf.uvws)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 5.728,  0.000,  0.000]\n",
      "bvect =  [ 2.864,  4.960,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  7.015]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 12\n",
      "natypes = 1\n",
      "symbols = ('Al',)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   5.728 |   4.960 |   0.000\n",
      "      1 |       1 |   7.159 |   2.480 |   0.000\n",
      "      2 |       1 |   4.296 |   2.480 |   0.000\n",
      "      3 |       1 |   8.591 |   4.960 |   0.000\n",
      "      4 |       1 |   1.432 |   0.827 |   2.338\n",
      "      5 |       1 |   4.296 |   0.827 |   2.338\n",
      "      6 |       1 |   2.864 |   3.307 |   2.338\n",
      "      7 |       1 |   5.728 |   3.307 |   2.338\n",
      "      8 |       1 |   5.728 |   1.653 |   4.677\n",
      "      9 |       1 |   4.296 |   4.134 |   4.677\n",
      "     10 |       1 |   7.159 |   4.134 |   4.677\n",
      "     11 |       1 |   2.864 |   1.653 |   4.677\n"
     ]
    }
   ],
   "source": [
    "print(sf.rcell)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The default a1vect_uvw and a2vect_uvw values are the two in-plane uvw rotation vectors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The crystal shift vectors:\n",
      "[-1.  1.  0.]\n",
      "[-1.  0.  1.]\n",
      "The Cartesian shift vectors:\n",
      "[ 5.72756493e+00 -5.57532102e-16 -8.29754091e-16]\n",
      "[ 2.86378246e+00  4.96021673e+00 -8.29754091e-16]\n"
     ]
    }
   ],
   "source": [
    "print('The crystal shift vectors:')\n",
    "print(sf.a1vect_uvw)\n",
    "print(sf.a2vect_uvw)\n",
    "print('The Cartesian shift vectors:')\n",
    "print(sf.a1vect_cart)\n",
    "print(sf.a2vect_cart)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As the StackingFault class was initialized with the conventional unit cell, the default shifting vectors are not the smallest possible lattice vectors.  The shift values can be manually set either 1. during initialization, 2. by setting to the a1vect_uvw, a2vect_uvw attributes after initialization, or 3. when calling one of the fault configuration generation methods.\n",
    "\n",
    "Note: the choice below is the most optimum for fcc {111} planes as the two shift vectors are the smallest non-parallel in-plane lattice vectors. The typical fcc {111} representation seen in papers with shifts of $\\frac{1}{2}[\\bar{1}10]$ and $\\frac{1}{2}[11\\bar{2}]$ vectors is actually a double cell and therefore requires sampling twice the area.  The GammaSurface class accounts for periodicity, meaning that the standard representation can be plotted based on measured results from the optimum grid of shifts."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The crystal shift vectors:\n",
      "[-0.5  0.5  0. ]\n",
      "[-0.5  0.   0.5]\n",
      "The Cartesian shift vectors:\n",
      "[ 2.86378246e+00 -2.78766051e-16 -4.14877046e-16]\n",
      "[ 1.43189123e+00  2.48010836e+00 -4.14877046e-16]\n"
     ]
    }
   ],
   "source": [
    "sf.a1vect_uvw = [-0.5, 0.5, 0.0]\n",
    "sf.a2vect_uvw = [-0.5, 0.0, 0.5]\n",
    "\n",
    "print('The crystal shift vectors:')\n",
    "print(sf.a1vect_uvw)\n",
    "print(sf.a2vect_uvw)\n",
    "print('The Cartesian shift vectors:')\n",
    "print(sf.a1vect_cart)\n",
    "print(sf.a2vect_cart)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.1.3. Build the free surface configuration\n",
    "\n",
    "The stacking fault configurations are modifications of the free surface configuration, so the next step is to build the free surface system.  For stacking fault configurations, two different parallel geometrical planes need to be positioned inside the system: the free surface cut plane and the fault plane.  Their positioning with respect to the atomic system is controlled by\n",
    "\n",
    "- __shift__ rigidly shifts the atoms. This is best used to position the cut plane\n",
    "- __faultpos_rel, faultpos_cart__ position the fault plane in the shifted system either at a relative coordinate or an absolute Cartesian coordinate, respectively. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.         0.         1.1691343 ]\n",
      " [0.         0.         3.50740289]\n",
      " [0.         0.         5.84567148]]\n"
     ]
    }
   ],
   "source": [
    "print(sf.shifts)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When building the free surface configuration, the default fault position corresponds to faultpos_rel = 0.5, i.e. it is placed in the center of the system.  If the number of replicas in the cut box vector direction are even, then this default fault position will result in the cut and fault planes bisecting the rotated cell along atomically equivalent planes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 5.728,  0.000,  0.000]\n",
      "bvect =  [ 2.864,  4.960,  0.000]\n",
      "cvect =  [ 0.000,  0.000, 28.059]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 48\n",
      "natypes = 1\n",
      "symbols = ('Al',)\n",
      "pbc = [ True  True False]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   5.728 |   4.960 |   1.169\n",
      "      1 |       1 |   7.159 |   2.480 |   1.169\n",
      "      2 |       1 |   4.296 |   2.480 |   1.169\n",
      "      3 |       1 |   8.591 |   4.960 |   1.169\n",
      "      4 |       1 |   1.432 |   0.827 |   3.507\n",
      "      5 |       1 |   4.296 |   0.827 |   3.507\n",
      "      6 |       1 |   2.864 |   3.307 |   3.507\n",
      "      7 |       1 |   5.728 |   3.307 |   3.507\n",
      "      8 |       1 |   5.728 |   1.653 |   5.846\n",
      "      9 |       1 |   4.296 |   4.134 |   5.846\n",
      "     10 |       1 |   7.159 |   4.134 |   5.846\n",
      "     11 |       1 |   2.864 |   1.653 |   5.846\n",
      "     12 |       1 |   5.728 |   4.960 |   8.184\n",
      "     13 |       1 |   7.159 |   2.480 |   8.184\n",
      "     14 |       1 |   4.296 |   2.480 |   8.184\n",
      "     15 |       1 |   8.591 |   4.960 |   8.184\n",
      "     16 |       1 |   1.432 |   0.827 |  10.522\n",
      "     17 |       1 |   4.296 |   0.827 |  10.522\n",
      "     18 |       1 |   2.864 |   3.307 |  10.522\n",
      "     19 |       1 |   5.728 |   3.307 |  10.522\n",
      "     20 |       1 |   5.728 |   1.653 |  12.860\n",
      "     21 |       1 |   4.296 |   4.134 |  12.860\n",
      "     22 |       1 |   7.159 |   4.134 |  12.860\n",
      "     23 |       1 |   2.864 |   1.653 |  12.860\n",
      "     24 |       1 |   5.728 |   4.960 |  15.199\n",
      "     25 |       1 |   7.159 |   2.480 |  15.199\n",
      "     26 |       1 |   4.296 |   2.480 |  15.199\n",
      "     27 |       1 |   8.591 |   4.960 |  15.199\n",
      "     28 |       1 |   1.432 |   0.827 |  17.537\n",
      "     29 |       1 |   4.296 |   0.827 |  17.537\n",
      "     30 |       1 |   2.864 |   3.307 |  17.537\n",
      "     31 |       1 |   5.728 |   3.307 |  17.537\n",
      "     32 |       1 |   5.728 |   1.653 |  19.875\n",
      "     33 |       1 |   4.296 |   4.134 |  19.875\n",
      "     34 |       1 |   7.159 |   4.134 |  19.875\n",
      "     35 |       1 |   2.864 |   1.653 |  19.875\n",
      "     36 |       1 |   5.728 |   4.960 |  22.214\n",
      "     37 |       1 |   7.159 |   2.480 |  22.214\n",
      "     38 |       1 |   4.296 |   2.480 |  22.214\n",
      "     39 |       1 |   8.591 |   4.960 |  22.214\n",
      "     40 |       1 |   1.432 |   0.827 |  24.552\n",
      "     41 |       1 |   4.296 |   0.827 |  24.552\n",
      "     42 |       1 |   2.864 |   3.307 |  24.552\n",
      "     43 |       1 |   5.728 |   3.307 |  24.552\n",
      "     44 |       1 |   5.728 |   1.653 |  26.890\n",
      "     45 |       1 |   4.296 |   4.134 |  26.890\n",
      "     46 |       1 |   7.159 |   4.134 |  26.890\n",
      "     47 |       1 |   2.864 |   1.653 |  26.890\n"
     ]
    }
   ],
   "source": [
    "surfacesystem = sf.surface(shift=sf.shifts[0], minwidth=15, even=True)\n",
    "print(surfacesystem)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.1.4. Check the free surface system and fault position\n",
    "\n",
    "Once the free surface configuration has been created, the quality of the fault position can be checked with the following class attributes:\n",
    "\n",
    "- __abovefault__ is a boolean mask indicating which atoms are above the fault plane. A good fault position should have (roughly) the same number of atoms above and below the plane.\n",
    "- __faultpos_rel__ is the relative position of the fault plane.\n",
    "- __faultpos_cart__ is the absolute Cartesian position of the fault plane."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "48 total atoms\n",
      "24 atoms above the fault\n",
      "\n",
      "Relative fault plane position: 0.5\n",
      "Absolute fault plane position: 14.029611541307906\n"
     ]
    }
   ],
   "source": [
    "print(f'{sf.system.natoms} total atoms')\n",
    "print(f'{sf.abovefault.sum()} atoms above the fault')\n",
    "print()\n",
    "print(f'Relative fault plane position: {sf.faultpos_rel}')\n",
    "print(f'Absolute fault plane position: {sf.faultpos_cart}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A different fault position than the default faultpos_rel=0.5 can be set either 1. when surface() is called, 2. by setting to either the faultpos_rel or faultpos_cart after calling surface(), or 3. when calling one of the fault configuration generation methods."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "48 total atoms\n",
      "20 atoms above the fault\n",
      "\n",
      "Relative fault plane position: 0.57\n",
      "Absolute fault plane position: 15.99375715709101\n"
     ]
    }
   ],
   "source": [
    "sf.faultpos_rel = 0.57\n",
    "\n",
    "print(f'{sf.system.natoms} total atoms')\n",
    "print(f'{sf.abovefault.sum()} atoms above the fault')\n",
    "print()\n",
    "print(f'Relative fault plane position: {sf.faultpos_rel}')\n",
    "print(f'Absolute fault plane position: {sf.faultpos_cart}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "48 total atoms\n",
      "24 atoms above the fault\n",
      "\n",
      "Relative fault plane position: 0.5\n",
      "Absolute fault plane position: 14.029611541307906\n"
     ]
    }
   ],
   "source": [
    "sf.faultpos_cart = 14.029611541307906\n",
    "\n",
    "print(f'{sf.system.natoms} total atoms')\n",
    "print(f'{sf.abovefault.sum()} atoms above the fault')\n",
    "print()\n",
    "print(f'Relative fault plane position: {sf.faultpos_rel}')\n",
    "print(f'Absolute fault plane position: {sf.faultpos_cart}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.1.5. Generate stacking fault configuration(s)\n",
    "\n",
    "A single stacking fault configuration for a specific shift can be generated using the fault() method.  A full 1D or 2D array of stacking fault configurations can be generated using the iterfaultmap() method."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "atoms in faultsystem are displaced by:\n",
      "[[ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 8.88178420e-16  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 8.88178420e-16  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00 -2.22044605e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00 -1.11022302e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00 -2.22044605e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00 -2.22044605e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00 -2.22044605e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00 -1.11022302e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00 -2.22044605e-16  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00  0.00000000e+00  0.00000000e+00]\n",
      " [ 1.43189123e+00 -2.22044605e-16  0.00000000e+00]]\n"
     ]
    }
   ],
   "source": [
    "faultsystem = sf.fault(a1=0.5, a2=0.0)\n",
    "print('atoms in faultsystem are displaced by:')\n",
    "print(am.displacement(surfacesystem, faultsystem))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Generate configurations along the slip line with StackingFault.iterfaultmap(). Note that the displacements may wrap due to periodic boundaries."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a1 = 0.0, a2 = 0.0, d = [ 0.000  0.000  0.000]\n",
      "a1 = 0.2, a2 = 0.0, d = [ 0.573  0.000  0.000]\n",
      "a1 = 0.4, a2 = 0.0, d = [ 1.146 -0.000  0.000]\n",
      "a1 = 0.6, a2 = 0.0, d = [ 1.718 -0.000  0.000]\n",
      "a1 = 0.8, a2 = 0.0, d = [ 2.291 -0.000  0.000]\n",
      "a1 = 0.0, a2 = 0.2, d = [ 0.286  0.496  0.000]\n",
      "a1 = 0.2, a2 = 0.2, d = [ 0.859  0.496  0.000]\n",
      "a1 = 0.4, a2 = 0.2, d = [ 1.432  0.496  0.000]\n",
      "a1 = 0.6, a2 = 0.2, d = [ 2.005  0.496  0.000]\n",
      "a1 = 0.8, a2 = 0.2, d = [ 2.577  0.496  0.000]\n",
      "a1 = 0.0, a2 = 0.4, d = [ 0.573  0.992  0.000]\n",
      "a1 = 0.2, a2 = 0.4, d = [ 1.146  0.992  0.000]\n",
      "a1 = 0.4, a2 = 0.4, d = [ 1.718  0.992  0.000]\n",
      "a1 = 0.6, a2 = 0.4, d = [ 2.291  0.992  0.000]\n",
      "a1 = 0.8, a2 = 0.4, d = [-2.864  0.992  0.000]\n",
      "a1 = 0.0, a2 = 0.6, d = [ 0.859  1.488  0.000]\n",
      "a1 = 0.2, a2 = 0.6, d = [ 1.432  1.488  0.000]\n",
      "a1 = 0.4, a2 = 0.6, d = [ 2.005  1.488  0.000]\n",
      "a1 = 0.6, a2 = 0.6, d = [ 2.577  1.488  0.000]\n",
      "a1 = 0.8, a2 = 0.6, d = [-2.577  1.488  0.000]\n",
      "a1 = 0.0, a2 = 0.8, d = [ 1.146  1.984  0.000]\n",
      "a1 = 0.2, a2 = 0.8, d = [ 1.718  1.984  0.000]\n",
      "a1 = 0.4, a2 = 0.8, d = [ 2.291  1.984  0.000]\n",
      "a1 = 0.6, a2 = 0.8, d = [ 0.000 -2.976  0.000]\n",
      "a1 = 0.8, a2 = 0.8, d = [-2.291  1.984  0.000]\n"
     ]
    }
   ],
   "source": [
    "for a1, a2, faultsystem in sf.iterfaultmap(num_a1=5, num_a2=5):\n",
    "    d = am.displacement(surfacesystem, faultsystem)[-1]\n",
    "    print(f'a1 = {a1:.1f}, a2 = {a2:.1f}, d = [{d[0]: 5.3f} {d[1]: 5.3f} {d[2]: 5.3f}]')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.2. fcc {111} using primitive unit cell\n",
    "\n",
    "Just like with the FreeSurface class, a primitive unit cell can be given with a conventional (hkl) slip plane by specifying what the conventional cell's setting/centering is.\n",
    "\n",
    "The advantages of doing this for StackingFaults are\n",
    "\n",
    "- the resulting systems will be smaller in the in-plane directions making DFT calculations easier, and\n",
    "- the default shifting vectors will be the smallest in-plane lattice vectors."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.2.1. Define an fcc primitive cell and initialize a StackingFault"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = uc.set_in_units(4.05, 'angstrom')\n",
    "atoms = am.Atoms(pos=[[0.0, 0.0, 0.0]])\n",
    "ucell = am.System(atoms=atoms, box=am.Box.trigonal(a/2**0.5, alpha=60), scale=True, symbols='Al')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "plane_hkl = [ 1,  1,  1]\n",
    "conventional_setting = 'f'\n",
    "sf = am.defect.StackingFault(plane_hkl, ucell, conventional_setting=conventional_setting)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.2.2. Check the identified rotated system and shift vectors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.  -0.5  0.5]\n",
      " [ 0.5 -0.5  0. ]\n",
      " [-1.  -1.  -1. ]]\n"
     ]
    }
   ],
   "source": [
    "print(sf.uvws)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 2.864,  0.000,  0.000]\n",
      "bvect =  [ 1.432,  2.480,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  7.015]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 3\n",
      "natypes = 1\n",
      "symbols = ('Al',)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   1.432 |   0.827 |   4.677\n",
      "      1 |       1 |   2.864 |   1.653 |   2.338\n",
      "      2 |       1 |   1.432 |   2.480 |   0.000\n"
     ]
    }
   ],
   "source": [
    "print(sf.rcell)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The crystal shift vectors:\n",
      "[ 0.  -0.5  0.5]\n",
      "[ 0.5 -0.5  0. ]\n",
      "The Cartesian shift vectors:\n",
      "[ 2.86378246e+00  2.86439546e-16 -2.38358656e-16]\n",
      "[ 1.43189123e+00  2.48010836e+00 -2.46533587e-16]\n"
     ]
    }
   ],
   "source": [
    "print('The crystal shift vectors:')\n",
    "print(sf.a1vect_uvw)\n",
    "print(sf.a2vect_uvw)\n",
    "print('The Cartesian shift vectors:')\n",
    "print(sf.a1vect_cart)\n",
    "print(sf.a2vect_cart)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we have an rcell with 1/4 the atoms and the algorithm automatically identified the same \"best\" shifts that we had to manually specify for the conventional cell!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.2.3. Build the free surface configuration\n",
    "\n",
    "The __vacuumwidth__ parameter of surface() inserts a volume of vacuum at the free surface of this width. DFT calculations are more efficient for free surfaces introduced with a volume of vacuum rather than making one dimension non-periodic.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 2.864,  0.000,  0.000]\n",
      "bvect =  [ 1.432,  2.480,  0.000]\n",
      "cvect =  [ 0.000,  0.000, 48.059]\n",
      "origin = [ 0.000,  0.000, -10.000]\n",
      "natoms = 12\n",
      "natypes = 1\n",
      "symbols = ('Al',)\n",
      "pbc = [ True  True False]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   1.432 |   0.827 |   5.846\n",
      "      1 |       1 |   2.864 |   1.653 |   3.507\n",
      "      2 |       1 |   1.432 |   2.480 |   1.169\n",
      "      3 |       1 |   1.432 |   0.827 |  12.860\n",
      "      4 |       1 |   2.864 |   1.653 |  10.522\n",
      "      5 |       1 |   1.432 |   2.480 |   8.184\n",
      "      6 |       1 |   1.432 |   0.827 |  19.875\n",
      "      7 |       1 |   2.864 |   1.653 |  17.537\n",
      "      8 |       1 |   1.432 |   2.480 |  15.199\n",
      "      9 |       1 |   1.432 |   0.827 |  26.890\n",
      "     10 |       1 |   2.864 |   1.653 |  24.552\n",
      "     11 |       1 |   1.432 |   2.480 |  22.214\n"
     ]
    }
   ],
   "source": [
    "surfacesystem = sf.surface(shift=sf.shifts[0], minwidth=15, even=True, vacuumwidth=20)\n",
    "print(surfacesystem)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.2.4. Check the free surface system and fault position\n",
    "\n",
    "The vacuum region changes the box dimensions but not the Cartesian atomic positions.  As such, the Cartesian fault positions are the same with and without the vacuum region, but the relative fault positions are different for all but one value.  Half of the vacuum region is added to the bottom of the system (by shifting origin) and the other half is added to the top. This means that a relative shift of 0.5 results in the same Cartesian location."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12 total atoms\n",
      "6 atoms above the fault\n",
      "\n",
      "Relative fault plane position: 0.5\n",
      "Absolute fault plane position: 14.029611541307904\n"
     ]
    }
   ],
   "source": [
    "print(f'{sf.system.natoms} total atoms')\n",
    "print(f'{sf.abovefault.sum()} atoms above the fault')\n",
    "print()\n",
    "print(f'Relative fault plane position: {sf.faultpos_rel}')\n",
    "print(f'Absolute fault plane position: {sf.faultpos_cart}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12 total atoms\n",
      "5 atoms above the fault\n",
      "\n",
      "Relative fault plane position: 0.57\n",
      "Absolute fault plane position: 17.39375715709101\n"
     ]
    }
   ],
   "source": [
    "sf.faultpos_rel = 0.57\n",
    "\n",
    "print(f'{sf.system.natoms} total atoms')\n",
    "print(f'{sf.abovefault.sum()} atoms above the fault')\n",
    "print()\n",
    "print(f'Relative fault plane position: {sf.faultpos_rel}')\n",
    "print(f'Absolute fault plane position: {sf.faultpos_cart}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12 total atoms\n",
      "6 atoms above the fault\n",
      "\n",
      "Relative fault plane position: 0.5000000000000001\n",
      "Absolute fault plane position: 14.029611541307906\n"
     ]
    }
   ],
   "source": [
    "sf.faultpos_cart = 14.029611541307906\n",
    "\n",
    "print(f'{sf.system.natoms} total atoms')\n",
    "print(f'{sf.abovefault.sum()} atoms above the fault')\n",
    "print()\n",
    "print(f'Relative fault plane position: {sf.faultpos_rel}')\n",
    "print(f'Absolute fault plane position: {sf.faultpos_cart}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.2.5. Generate stacking fault configuration(s)\n",
    "\n",
    "Further support for DFT is that the fault() and iterfaultmap() methods also have a __minimum_r__ parameter that can be used to ensure all atoms across the fault plane remain at least a set distance apart.  This can help with relaxations when certain faults may otherwise position atoms very close together."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, minimum_r is set to be 0.85 of the unit cell's smallest interatomic vector r0. This results in some shifts in the z direction for certain fault configurations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a1 = 0.0, a2 = 0.0, d = [ 0.000  0.000  0.000]\n",
      "a1 = 0.2, a2 = 0.0, d = [ 0.573  0.000  0.000]\n",
      "a1 = 0.4, a2 = 0.0, d = [ 1.146  0.000  0.000]\n",
      "a1 = 0.6, a2 = 0.0, d = [-1.146  0.000  0.000]\n",
      "a1 = 0.8, a2 = 0.0, d = [-0.573  0.000  0.000]\n",
      "a1 = 0.0, a2 = 0.2, d = [ 0.286  0.496  0.000]\n",
      "a1 = 0.2, a2 = 0.2, d = [ 0.859  0.496  0.004]\n",
      "a1 = 0.4, a2 = 0.2, d = [-1.432  0.496  0.073]\n",
      "a1 = 0.6, a2 = 0.2, d = [-0.859  0.496  0.004]\n",
      "a1 = 0.8, a2 = 0.2, d = [-0.286  0.496  0.000]\n",
      "a1 = 0.0, a2 = 0.4, d = [ 0.573  0.992  0.000]\n",
      "a1 = 0.2, a2 = 0.4, d = [ 1.146  0.992  0.073]\n",
      "a1 = 0.4, a2 = 0.4, d = [-1.146  0.992  0.073]\n",
      "a1 = 0.6, a2 = 0.4, d = [-0.573  0.992  0.000]\n",
      "a1 = 0.8, a2 = 0.4, d = [-0.000  0.992  0.000]\n",
      "a1 = 0.0, a2 = 0.6, d = [-0.573 -0.992  0.000]\n",
      "a1 = 0.2, a2 = 0.6, d = [ 0.000 -0.992  0.004]\n",
      "a1 = 0.4, a2 = 0.6, d = [ 0.573 -0.992  0.000]\n",
      "a1 = 0.6, a2 = 0.6, d = [ 1.146 -0.992  0.000]\n",
      "a1 = 0.8, a2 = 0.6, d = [-1.146 -0.992  0.000]\n",
      "a1 = 0.0, a2 = 0.8, d = [-0.286 -0.496  0.000]\n",
      "a1 = 0.2, a2 = 0.8, d = [ 0.286 -0.496  0.000]\n",
      "a1 = 0.4, a2 = 0.8, d = [ 0.859 -0.496  0.000]\n",
      "a1 = 0.6, a2 = 0.8, d = [ 1.432 -0.496  0.000]\n",
      "a1 = 0.8, a2 = 0.8, d = [-0.859 -0.496  0.000]\n"
     ]
    }
   ],
   "source": [
    "for a1, a2, faultsystem in sf.iterfaultmap(num_a1=5, num_a2=5, minimum_r=0.85*ucell.r0()):\n",
    "    d = am.displacement(surfacesystem, faultsystem)[-1]\n",
    "    print(f'a1 = {a1:.1f}, a2 = {a2:.1f}, d = [{d[0]: 5.3f} {d[1]: 5.3f} {d[2]: 5.3f}]')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.3. hcp {0001} slip plane\n",
    "\n",
    "The system rotation vectors and the shifting vectors can be given in Miller-Bravais indices if the reference unit cell is hexagonal."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.3.1. Define an fcc primitive cell and initialize a StackingFault"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = uc.set_in_units(3.18, 'angstrom')\n",
    "c = uc.set_in_units(5.17, 'angstrom')\n",
    "atoms = am.Atoms(pos=[[0.0, 0.0, 0.0], [1/3, 2/3, 0.5]])\n",
    "ucell = am.System(atoms=atoms, box=am.Box.hexagonal(a, c), scale=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "plane_hkl = [ 0,  0,  0,  1]\n",
    "\n",
    "sf = am.defect.StackingFault(plane_hkl, ucell)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.3.2. Check the identified rotated system and shift vectors\n",
    "\n",
    "If plane_hkl was given in the 4-index representation, then uvws, a1vect_uvw and a2vect_uvw will be saved in the 4-index representation as well."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.66666667 -0.33333333 -0.33333333  0.        ]\n",
      " [ 0.33333333  0.33333333 -0.66666667  0.        ]\n",
      " [ 0.          0.         -0.          1.        ]]\n"
     ]
    }
   ],
   "source": [
    "print(sf.uvws)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 3.180,  0.000,  0.000]\n",
      "bvect =  [ 1.590,  2.754,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  5.170]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 2\n",
      "natypes = 1\n",
      "symbols = (None,)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   0.000 |   0.000 |   0.000\n",
      "      1 |       1 |   3.180 |   1.836 |   2.585\n"
     ]
    }
   ],
   "source": [
    "print(sf.rcell)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The crystal shift vectors:\n",
      "[ 0.66666667 -0.33333333 -0.33333333  0.        ]\n",
      "[ 0.33333333  0.33333333 -0.66666667  0.        ]\n",
      "The Cartesian shift vectors:\n",
      "[ 3.18000000e+00 -2.73153518e-16  0.00000000e+00]\n",
      "[1.59       2.75396078 0.        ]\n"
     ]
    }
   ],
   "source": [
    "print('The crystal shift vectors:')\n",
    "print(sf.a1vect_uvw)\n",
    "print(sf.a2vect_uvw)\n",
    "print('The Cartesian shift vectors:')\n",
    "print(sf.a1vect_cart)\n",
    "print(sf.a2vect_cart)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The remaining steps are similar to those mentioned for the other systems above."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
